<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
      content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
<title>执行任务</title>
<%@ include file="/include/mobilelibs.jsp" %>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=e9ICdBVcGY1GQqIQ8QwmhVKDMKwMyMzq"></script>
<script>
    $(function () {
        "use strict";
        var status = '${ct.status}';
        if (status == 'DOING') {
            $('#startFooter').artEditor({
                limitSize: 1, // 兆
                showServer: false,
                uploadUrl: '',
                data: {},
                uploadField: 'image',
                placeholader: '<p>您未输入详细的任务文字说明...</p>',
                validHtml: [ "br" ],
                uploadSuccess: function (res) {
                    return res.path;
                },
                uploadError: function (res) {
                    console.log(res);
                }

            });
        }
        $.get("getJsApiConfigParams.json?url=" + encodeURIComponent(location.href.split('#')[0]), function (params) {
            if (params && params["appId"]) {
                wx.config({
                    debug: false,
                    appId: params["appId"],
                    timestamp: params["timestamp"],
                    nonceStr: params["nonceStr"],
                    signature: params["signature"],
                    jsApiList: [
                        'checkJsApi',
                        'onMenuShareTimeline',
                        'onMenuShareAppMessage',
                        'onMenuShareQQ',
                        'onMenuShareWeibo',
                        'scanQRCode',
                        'chooseImage',
                        'uploadImage',
                        'downloadImage'
                    ]
                });
            }
        });
    });
</script>
<style>
.photoContainer {
    width: 100%;
    min-height: 10.8rem;
    background-color: #FFFFFF;
    overflow: hidden;
}

.startImg {
    width: 3.8rem;
    height: 4.2rem;
    border-radius: 0.4rem;
    margin-left: 0.7rem;
    margin-top: 0.5rem;
    float: left;
    
}

.add {
    width: 3.8rem;
    height: 4.2rem;
    border-radius: 0.4rem;
    margin-left: 0.7rem;
    margin-top: 0.5rem;
    background-color: #f5f5f5;
    background: url(images/taskStart/add.png) no-repeat center center;
    float: left;
}

.taskStartFooter {
    width: 100%;
    /*height: 5.5rem;*/
    border-top: 0.4rem solid #FFFFFF;
    border-bottom: 0.8rem solid #FFFFFF;
    padding: 0.6rem 0.8rem 0 0.6rem;
    font-family: "微软雅黑";
    word-wrap:break-word;
  
}

.mui-preview-image.mui-fullscreen {
    position: fixed;
    z-index: 20;
    background-color: #000;
}

.mui-preview-header,
.mui-preview-footer {
    position: absolute;
    width: 100%;
    left: 0;
    z-index: 10;
}

.mui-preview-header {
    height: 44px;
    top: 0;
}

.mui-preview-footer {
    height: 50px;
    bottom: 0px;
}

.mui-preview-header .mui-preview-indicator {
    display: block;
    line-height: 25px;
    color: #fff;
    text-align: center;
    margin: 15px auto 4;
    width: 70px;
    background-color: rgba(0, 0, 0, 0.4);
    border-radius: 12px;
    font-size: 16px;
}

.mui-preview-image {
    display: none;
    -webkit-animation-duration: 0.5s;
    animation-duration: 0.5s;
    -webkit-animation-fill-mode: both;
    animation-fill-mode: both;
}

.mui-preview-image.mui-preview-in {
    -webkit-animation-name: fadeIn;
    animation-name: fadeIn;
}

.mui-preview-image.mui-preview-out {
    background: none;
    -webkit-animation-name: fadeOut;
    animation-name: fadeOut;
}

.mui-preview-image.mui-preview-out .mui-preview-header,
.mui-preview-image.mui-preview-out .mui-preview-footer {
    display: none;
}

.mui-zoom-scroller {
    position: absolute;
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    align-items: center;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    justify-content: center;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    -webkit-backface-visibility: hidden;
}

.mui-zoom {
    -webkit-transform-style: preserve-3d;
    transform-style: preserve-3d;
}

.mui-slider .mui-slider-group .mui-slider-item img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
}

.mui-android-4-1 .mui-slider .mui-slider-group .mui-slider-item img {
    width: 100%;
}

.mui-android-4-1 .mui-slider.mui-preview-image .mui-slider-group .mui-slider-item {
    display: inline-table;
}

.mui-android-4-1 .mui-slider.mui-preview-image .mui-zoom-scroller img {
    display: table-cell;
    vertical-align: middle;
}

.mui-preview-loading {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    display: none;
}

.mui-preview-loading.mui-active {
    display: block;
}

.mui-preview-loading .mui-spinner-white {
    position: absolute;
    top: 50%;
    left: 50%;
    margin-left: -25px;
    margin-top: -25px;
    height: 50px;
    width: 50px;
}

.mui-preview-image img.mui-transitioning {
    -webkit-transition: -webkit-transform 0.5s ease, opacity 0.5s ease;
    transition: transform 0.5s ease, opacity 0.5s ease;
}

@-webkit-keyframes fadeIn {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

@keyframes fadeIn {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

@-webkit-keyframes fadeOut {
    0% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

@keyframes fadeOut {
    0% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

#deletePhoto {
    display: none;
    position: fixed;
    bottom: 10px;
    left: 50%;
    margin-left: -27px;
}
.detailBtnStart{
	      width: 5.5rem;
				height: 2.1rem;
				font-family: "黑体";
				font-size: 0.9rem;
				background: #3abd8a !important;
				color: #FFFFFF !important;
}
</style>
</head>

<body>
<form method="post" class="form-horizontal" action="<c:url value="/submitTask.json" />"
      id="taskForm">
    <input type="hidden" name="id" value="${id}">
    <input type="hidden" name="userId" value="${userId}">
    <input type="hidden" id="status" name="status" value="0">
    <input type="hidden" id="imageUrl" name="imageUrl">
    <input type="hidden" id="taskDesc" name="taskDesc">

    <div class="mui-content">
        <div class="taskTip">
            <span>任务指引</span>
        </div>
        <div class="detailFooter">
            <div class="footerFont">
                ${pt.taskGuidanceWords}
            </div>
            <div class="DetailImg">
                <c:forEach var="imageUrl" items="${pt.imagesList}"
                           varStatus="status">
                    <img style="width: 150px; height: 150px;" src="${imageUrl}">
                </c:forEach>
            </div>
        </div>
        <div class="taskPhoto">
            <span>拍照</span>
        </div>
        <div class="photoContainer mui-content-padded" id="photoContainer" style="margin: 0;">
            <c:forEach var="imageUrl" items="${ft.imagesList}" varStatus="status">
                <img style="width:3.8rem;height:3.8rem;float:left" src="${imageUrl}" class="startImg" id="img1"
                     data-preview-src="" data-preview-group="1">
            </c:forEach>
            <c:if test="${ct.status =='DOING' }">
                <div class="add imgPlace" id="image"></div>
            </c:if>
        </div>
        <div class="taskText">
            <span>任务文字说明</span>
        </div>
        <div class="taskStartFooter" id="startFooter" name="taskDesc">${ft.taskDesc}</div>
         <c:if test="${ct.status =='DOING' }">
        <div id="taskStartBtn" class="addHeight">
           
                <button id=""
                        class="mui-btn mui-btn-success mui-btn-outlined detailBtnStart" onmousedown="changeStatus()">提交
                </button>       
        </div>
      </c:if>
    </div>
    <input type="hidden" id="sourceUrl"/>
    <button id="deletePhoto" type="button" class="mui-btn mui-btn-danger mui-btn-outlined">删除</button>
</form>
<script>
    var status = '${ct.status}';
    mui.previewImage({
        openCallback: function (index, ele) {
            if (status == 'DOING') {
                $('#deletePhoto').show().appendTo(ele);

            }
        }
    });
    mui(".photoContainer").on('tap', '.startImg', function () {
        $("#sourceUrl").val($(this).attr("glod"));
    });
    $("#deletePhoto").click(function () {
        if (confirm("确定要删除图片")) {
            $("#deletePhoto").hide();
            var delUrl = $("#sourceUrl").val();
            var imageUrl = $("#imageUrl").val()
            var urls = imageUrl.split(",");
            var imageTotal = [];
            for (var i = 0; i < urls.length; i++) {
                if (urls[i] == delUrl) {
                    $("img[glod='" + delUrl + "']").remove();
                    mui.alert("删除成功，点击屏幕返回");
                } else {
                    imageTotal.push(urls[i]);
                }
            }
            $("#imageUrl").val(imageTotal);
        }
    });
    function changeStatus() {
        $("#status").val("1");
        $("#taskDesc").val($("#startFooter").html());
    }
    var imageTotal = [];
    //var div = $("#image");
    //var images = {localIds:[],serverId:[]};
    wx.ready(function () {
        $('.imgPlace').click(function () {
            var images = {localIds: [], serverId: []};
            var div = $("#image");
            wx.chooseImage({
                count: 9,
                sizeType: ['original', 'compressed'],
                sourceType: ['camera'],
                success: function (res) {
                    images.localIds = res.localIds;
                    var i = 0;
                    var length = images.localIds.length;
                    var upload = function () {
                        var local = images.localIds[i];
                        wx.uploadImage({
                            localId: images.localIds[i],
                            success: function (res) {
                                images.serverId.push(res.serverId);
                                var y = i + 1;
                                var img = '<img id="smallImg' + y + '" src="' + local + '"  class="startImg"   data-preview-src="" data-preview-group="1" onclick="setSrc()" glod="' + res.serverId + '"/> '
                                div.after(img);
                                imageTotal.push(res.serverId);
                                $("#imageUrl").val(imageTotal);
                                //如果还有照片，继续上传
                                i++;
                                if (i < length) {
                                    upload();
                                }
                            }
                        });
                    };

                    upload();
                }
            });
            mui.previewImage();
        });
    });

    wx.error(function(res){
        console.log(res);
    });

</script>
</body>

</html>